package com.corpgovernment.organization.controller;

import com.corpgovernment.api.organization.model.redemptioncode.GetRedemptionCodeRequest;
import com.corpgovernment.api.organization.model.redemptioncode.GetRedemptionCodeResponse;
import com.corpgovernment.api.organization.model.redemptioncode.RedemptionCodeVo;
import com.corpgovernment.api.organization.vo.DownloadResponse;
import com.corpgovernment.common.base.BaseUserInfo;
import com.corpgovernment.common.base.JSONResult;
import com.corpgovernment.job.controller.vo.job.PageBatchImportJobRecordReqVo;
import com.corpgovernment.job.controller.vo.job.PageBatchImportJobRecordRespVo;
import com.corpgovernment.organization.enumm.FileTemplateEnum;
import com.corpgovernment.organization.service.RedemptionCodeService;
import com.corpgovernment.organization.util.ExcelUtils;
import javax.servlet.http.HttpServletResponse;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

/**
 * @author xbqi
 * @date 2023/11/1
 */
@RestController
@RequestMapping("/redemptionCode")
@Slf4j
public class RedemptionCodeController {

    @Autowired
    private RedemptionCodeService redemptionCodeService;
    @Autowired
    private ExcelUtils excelUtils;
    @PostMapping("/listRedemptionCode")
    public JSONResult<GetRedemptionCodeResponse> listRedemptionCode(@RequestBody GetRedemptionCodeRequest request) {
        return JSONResult.success(redemptionCodeService.listRedemptionCode(request));
    }

    @PostMapping("/syncRedemptionCode")
    public JSONResult<DownloadResponse> syncRedemptionCode(@RequestParam("file") MultipartFile file, BaseUserInfo baseUserInfo) {
            return JSONResult.success(redemptionCodeService.syncRedemptionCode(file, baseUserInfo));
    }

    @RequestMapping("/downloadTemplate")
    public JSONResult<String> downloadTemplate(HttpServletResponse response) {
        return excelUtils.downloadTemplate(FileTemplateEnum.SyncRedemptionCodeTemplate.getDealCode(), response);
    }

    @GetMapping("/getRedemptionCode")
    public JSONResult<RedemptionCodeVo> listRedemptionCode(@RequestParam("uid") String uid) {
        return JSONResult.success(redemptionCodeService.getRedemptionCode(uid));
    }

    @PostMapping("/pageBatchImportRedemption")
    public JSONResult<PageBatchImportJobRecordRespVo> pageBatchImportRedemption(@RequestBody PageBatchImportJobRecordReqVo requestParam) {
        return new JSONResult<>(redemptionCodeService.pageBatchImportRedemption(requestParam));
    }

}
